package org.example.Day11.TCP;

import java.io.DataInputStream;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args)throws Exception{
        System.out.println("----服务端启动成功----");
        //创建ServerSocket对象并注册窗口
        ServerSocket serverSocket = new ServerSocket(8888);

        //使用ServerSocket对象
        Socket socket = serverSocket.accept();
        //socket得到一个字节流
        InputStream is = socket.getInputStream();
        //把原始字节流输入流包装成输出流
        DataInputStream dis = new DataInputStream(is);

        //使用数据输入流读取客户端送来的消息
        String rs = dis.readUTF();
        System.out.println(rs);
        System.out.println(socket.getRemoteSocketAddress());
        dis.close();
        socket.close();
    }
}
